package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.FeedbackPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ToastUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IFeedbackView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/5/9.
 * Desc   : 意见反馈act
 */

public class MyFeedbackActivity extends BaseActivity<FeedbackPresenter> implements IFeedbackView {

    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.view_bottomline)
    View viewBottomline;
    @BindView(R.id.et_feedback)
    EditText etFeedback;
    @BindView(R.id.ll_write_feedback)
    LinearLayout llWriteFeedback;
    @BindView(R.id.ll_success)
    LinearLayout llSuccess;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;
    private String token;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_my_feedback);
        token = SharedPreferencesUtil.getsInstances(this).getLoginInfo().getToken();
    }

    @Override
    protected void initPresenter() {
        mPresenter = new FeedbackPresenter(this);
    }

    @Override
    protected void init() {
        setTopView();
    }

    private void setTopView() {
        imgLeft.setImageResource(R.mipmap.icon_close_black);
        txtTitle.setText("意见反馈");
        viewBottomline.setVisibility(View.VISIBLE);
    }

    @OnClick({R.id.ll_leftview, R.id.btn_confirm})
    public void onViewClicked(View view) {
        String content = etFeedback.getText().toString().trim();
        switch (view.getId()) {
            case R.id.ll_leftview:
                finish();
                break;
            case R.id.btn_confirm:
                if (!content.equals("")) {
                    mPresenter.submit(token, content);
                } else {
                    ToastUtils.showToast("反馈内容不能为空");
                }
                break;
        }
    }

    @Override
    public void submitSuccess(String data) {
        ToastUtils.showToast(data);
        llWriteFeedback.setVisibility(View.GONE);
        llSuccess.setVisibility(View.VISIBLE);
    }
}
